package com.googlecode.pdfToCMaker;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.util.PDFMergerUtility;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by ayacub on 12/5/13.
 */
public class PDFUtil {


    public static void combinePDF(List<File> input, String outputPath) {
        try {
            PDFMergerUtility merger = new PDFMergerUtility();
            for (File inputFile : input) {
                merger.addSource(inputFile);
            }
            merger.setDestinationFileName(outputPath);
            merger.mergeDocuments();
        }
        catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static int getPageCount(File file) {
        try {
            PDDocument document = PDDocument.load(file);
            int ret = document.getNumberOfPages();
            document.close();
            return ret;
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
